<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            容器库间转移确认
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">业务类型</div>
                    <div class="aui-list-item-input">
                        <select id="businessType" onchange="onChangeInBusiness()">
                        </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">调入库位</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择/扫描 调入库位" id="relWorkCellCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell('2')"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">容器条码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描容器条码" id="traynum" value="" onclick="getIdSelector();">
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-scan " style="padding-right:10px;font-size: 1.6rem"
                        onclick="doScan();"></i>
                </div>
            </li>

            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">容量</div>
                    <div class="aui-list-item-input">
                        <input type="number" id="qty">
                    </div>
                </div>
            </li>
            <!--  <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">调出库位</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择/扫描 调出库位" id="workCellCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell('1')"></i>
                </div>
            </li> -->


            <p></p>
            <p></p>
            <div class="aui-btn aui-btn-info aui-btn-block"><textarea type="text" class="aui-input"
                    style="width: 80%;font-size: 16px;" id="message"></textarea></div>
            <!-- <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:1px;">
                <table class="table" style='width:100%;' id="table">
                    <thead>
                        <tr
                            style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 8px;font-weight: bold;">
                            <td algin='center'>物料编码</td>
                            <td algin='center'>物料名称</td>
                            <td algin='center'>规格</td>
                            <td algin='center'>批次号</td>
                            <td algin='center'>数量</td>
                        </tr>
                    </thead>
                    <tbody id="tbodyHtml">
                    </tbody>
                </table>
            </div> -->
            <div style="background-color:white;width: 100%;margin-top:2%;margin-bottom:5px;">
                <table class="table" style='width:100%;' id="table">
                    <thead>
                        <tr
                            style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 8px;font-weight: bold;">
                            <td algin='center'>物料编码</td>
                            <td algin='center'>规格</td>
                            <td algin='center'>汇总数量</td>
                        </tr>
                    </thead>
                    <tbody id="tbodyHtml">
                    </tbody>
                </table>
            </div>
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label" style="margin-left:30%;width:100%">扫描箱数：</div>
                <div class="aui-list-item-input" style="margin-left:1%">
                    <input type="text" id="num" value="" disabled="true" style='color:red' />
                </div>
            </div>
        </ul>
        <ul class="ui-selectee" id="tbodyHtmlS">

        </ul>

        <p></p>
        <p></p>
        <div style="height:60px;"></div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <!-- <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div> -->
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()" id="submitButton">一键入库</div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var workCellGid = ""; //调出库位GID
    var workCellCode = ""; //调出库位编码
    var workCellName = ""; //调出库位名称
    var relWorkCellGid = ""; //调入库位GID
    var relWorkCellCode = ""; //调入库位编码
    var relWorkCellName = ""; //调入库位名称
    var subBussinessType = "";//子业务类型

    var scanRule = ""; //条码解析规则
    var code = "";//菜单路由参数 业务类型

    var arrSave = [];
    var rsCodeList = "";
    var num = 0;
    var listTotal = []

    //初始化查询仓库下拉框
    apiready = function () {

        $("#relWorkCellCode").focus();
        idSelector = "relWorkCellCode";

        $("#num").val(0);

        var query = api.pageParam.query;
        subBussinessType = query.subBussinessType;
        code = query.code;
        var title = query.title;
        if (title != undefined && title != null && title != "") {
            document.getElementById("title").innerHTML = title;
        }
        var businessTypeDisable = query.typeDisable;//是否禁用业务类型
        if (businessTypeDisable != undefined && businessTypeDisable != null && businessTypeDisable == "Y") {
            $("#businessType").attr('disabled', true);
        }

        //查询业务类型下拉框
        doSearchBusinessType();
    }

    //业务类型下拉框
    function doSearchBusinessType() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getBusinessType";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                type: 'IN',
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var map = eval("(" + data + ")");
                var list = eval(map.list);
                var html = "<option value=''>--请选择--</option>";
                for (var i = 0; i < list.length; i++) {
                    html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                }
                $api.html($api.byId("businessType"), html);
                $("#businessType").val(code);
            }
        });
    }

    //业务类型下拉框值改变
    function onChangeInBusiness() {
        var businessType = $("#businessType").val();
        //源仓库不为空，查询库位下拉框
        if (businessType != "" && businessType != null && businessType != undefined) {
            var serverUrl = localStorage.getItem('serverUrl');
            var un = localStorage.getItem('un');
            var url = serverUrl + "/app/getSubBusinessType";
            var data = {
                values: { ////以表单方式提交参数（JSON对象）
                    type: 'IN',
                    businessType: businessType,
                    un: un
                }
            };
            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                timeout: 300,
                returnAll: false,
                data: data
            }, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var map = eval("(" + data + ")");
                    var list = eval(map.list);
                    var html = "<option value=''>--请选择--</option>";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].sysid + "'>" + list[i].name + "</option>";
                    }
                    $api.html($api.byId("subBusinessType"), html);
                }
            });
        } else {

        }


    }


    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }



    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {

            //1：调出库位
            if (idSelector == 'workCellCode') {

                $("#workCellCode").val(ret);
                //查询调出库位
                getWorkCell(ret, idSelector, "1");

                //24：调入库位
            } else if (idSelector == 'relWorkCellCode') {

                $("#relWorkCellCode").val(ret);
                //查询调入库位
                getWorkCell(ret, idSelector, "2");

                //5：扫描容器条码
            } else if (idSelector == 'traynum') {
                $("#traynum").val(ret);

                // 查询容器条码是否可以一键入库
                doSerchRsCode(ret);
            }
        });
    }

    //7:库位扫描校验
    function getWorkCell(code, inputId, flag) {
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: {
                flag: "out_kj", //库内库间标识（out_kn库内  out_kj库间,in_rk入库出库）
                workCenterGid: "", //仓库GID
                workCellCode: code, //库位编码
                relWorkCellGid: "", //调入库位
                tm: "",
                workCellFlag: "", //原库位调入库位flag
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    //源库位
                    if (flag == "1") {

                        workCellGid = list[0].workCellGid;
                        workCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                        workCellName = list[0].workCellName;
                        document.getElementById(inputId).value = workCellCode;
                        $("#boxnum").focus();
                        idSelector = "boxnum";

                        //调入库位
                    } else if (flag == "2") {

                        relWorkCellGid = list[0].workCellGid;
                        relWorkCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                        relWorkCellName = list[0].workCellName;
                        document.getElementById(inputId).value = relWorkCellCode;
                        $("#workCellCode").focus();
                        idSelector = "workCellCode";
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#" + inputId).focus();
                    $("#" + inputId).select();
                }
            }
        });
    }

    //8：选择库位
    function goSelectWorkCell(workCellFlag) {
        var tm = $("#tm").val();
        api.openWin({
            name: 'uwmSelectWorkCell',
            url: 'uwmSelectWorkCell.html',
            pageParam: {
                flag: "out_kj",
                name: "uwmInterBankTransferByTrayConfirmVesselInTransfer",
                tm: tm,
                workCenterGid: "",
                relWorkCellGid: relWorkCellGid,
                workCellFlag: workCellFlag
            }
        });
    }

    //库位选择后回调函数
    function setWorkCell(id, code, name, workCellFlag) {

        //源库位
        if (workCellFlag == "1") {

            workCellGid = id;
            workCellCode = code;
            workCellName = name;
            document.getElementById('workCellCode').value = code + ":" + name;

            //调入库位
        } else if (workCellFlag == "2") {

            relWorkCellGid = id;
            relWorkCellCode = code;
            relWorkCellName = name;
            document.getElementById('relWorkCellCode').value = code + ":" + name;
            $("#workCellCode").focus();
            var e = "workCellCode";
            idSelector = e;
        }
    }

    //9；PDA自带扫描回车事件-源库位
    $("#workCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#workCellCode").val(sm);
            getWorkCell(sm, "workCellCode", "1");
        }
    });

    //10；PDA自带扫描回车事件-调入库位
    $("#relWorkCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#relWorkCellCode").val(sm);
            getWorkCell(sm, "relWorkCellCode", "2");
        }
    });

    //保存按钮
    function save() {
        if (!clickThrottle()) {
            return;
        }

        var businessType = $("#businessType").val();
        //托号
        var traynum = $("#traynum").val();

        const submitButton = document.getElementById('submitButton');

        submitButton.style.pointerEvents = "none"

        //业务类型非空校验
        if (businessType == "" || businessType == null || businessType == undefined) {
            api.toast({
                msg: '请选择业务类型',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }
        //调入库位非空校验
        if (relWorkCellGid == "" || relWorkCellGid == null || relWorkCellGid == undefined) {
            api.toast({
                msg: '请选择/扫描 调入库位',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }

        //箱码非空校验
        // if (traynum == "" || traynum == null || traynum == undefined) {
        //     api.toast({
        //         msg: '容器条码不能为空',
        //         duration: 3000
        //     });
        //     submitButton.style.pointerEvents = "auto"
        //     return;
        // }

        //源仓库和目标仓库不能一样
        if (workCellGid != null && workCellGid != "" && workCellGid == relWorkCellGid) {
            api.toast({
                msg: '源库位和调入库位不能一样',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }

        if (arrSave.length == 0) {
            api.toast({
                msg: '没有需要一键入库的数据，请扫描容器条码',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }
        var arrSavelength = parseInt(arrSave.length)

        var ctBarRedis = []
        arrSave.forEach(item => {
            ctBarRedis.push(item.rsBarcode);
        });
        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/uwmQualifyInConfirm";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                businessType: businessType, //业务类型
                relWorkCellGid: relWorkCellGid, // 调入库位
                workCellGid: workCellGid, //源库位编码
                traynum: traynum, //容器条码
                list: JSON.stringify(arrSave),
                subBussinessType: subBussinessType,
                un: un
                ,ctBarRedis:JSON.stringify(ctBarRedis)
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                console.log(JSON.stringify(myobj))
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    listTotal = list

                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    }); //清空表单
                    var listlength = parseInt(list.length)
                    var newmessage = "总共确认" + arrSavelength + "箱，成功" + (arrSavelength - listlength) + "箱，失败" + listlength + "箱"
                    $("#message").val(newmessage);

                    // getBoxInfoByTray(traynum, 2);

                    $("#traynum").focus();
                    $("#traynum").select();

                    if (listlength == 0) {
                        //清空表格数据
                        $api.html($api.byId("tbodyHtml"), "");
                        $("#num").val(0);
                        arrSave = [];
                        num = 0;
                        rsCodeList = ""
                    }else {
                        rsCodeList = myobj.rsCodeList
                    }

                    var lists = eval(myobj.listB);
                    var html = "";
                    var qty = 0;
                    for (var i = 0; i < lists.length; i++) {
                        qty = qty + Number(lists[i].qty);
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        html += "<td name='mrlCode'>" + lists[i].mrlCode + "</td>";
                        html += "<td name='drawing'>" + lists[i].drawing + "</td>";                       
                        html += "<td name='qty'>" + lists[i].qty + "</td>";
                        html += "</tr>";
                    }
                    $("#qty").val(qty);
                    $api.html($api.byId("tbodyHtml"), html);

                    setTable(arrSave, list);


                } else if (myobj.code == '1') {
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    $("#message").val(myobj.message);
                    // getBoxInfoByTray(traynum, 3);
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#traynum").focus();
                    $("#traynum").select();
                }
            } else {
                api.hideProgress();
                submitButton.style.pointerEvents = "auto"
            }
        });
    }



    //自动保存
    function saveAuto() {

        //物料号
        var mrlCode = $("#mrlCode").val();
        //批次号
        var lotCode = $("#lotCode").val();
        //转移数量数量
        var qty = $("#qty").val();
        //条码
        var tm = $("#tm").val();
        //箱号
        var boxnum = $("#boxnum").val();

        //调入库位非空校验
        if (relWorkCellGid == "" || relWorkCellGid == null || relWorkCellGid == undefined) {
            return;
        }

        //箱码非空校验
        if (boxnum == "" || boxnum == null || boxnum == undefined) {
            return;
        }

        //物料非空校验
        if (mrlCode == "" || mrlCode == null || mrlCode == undefined) {
            return;
        }

        //批次号非空校验
        if (lotCode == "" || lotCode == null || lotCode == undefined) {
            return;
        }

        //转移数量非空校验
        if (qty == "" || qty == null || qty == undefined) {
            return;
        } else {
            if (parseFloat(qty) <= 0) {
                return;
            }
        }

        //源仓库和目标仓库不能一样
        if (workCellGid != null && workCellGid == relWorkCellGid) {
            return;
        }

        //保存
        save();
    }

    //扫描之后条码解析
    function tmSplit(sm) {
        $("#tm").val(sm);
        //直接解析
        if (scanRule == "old") {

            //本地解析
            localAnalyze(sm);

        } else {

            //后台解析
            postAnalyze(sm);
        }
    }

    //本地解析
    function localAnalyze(sm) {
        var arr = sm.split(",");
        if (arr[1] == null || arr[1] == undefined) {
            $("#mrlCode").val("");
        } else {
            $("#mrlCode").val(arr[1]);
        }
        if (arr[2] == null || arr[2] == undefined) {
            $("#qty").val("");
        } else {
            $("#qty").val(arr[2]);
        }
        if (arr[3] == null || arr[3] == undefined) {
            $("#lotCode").val("");
        } else {
            $("#lotCode").val(arr[3]);
        }
        if (arr[4] == null || arr[4] == undefined) {
            $("#tmID").val("");
        } else {
            $("#tmID").val(arr[4]);
        }
        if (arr[9] == null || arr[9] == undefined) {
            $("#boxnum").val("");
        } else {
            $("#boxnum").val(arr[9]);
        }

        //自动保存
        saveAuto();
    }

    //后台解析条码
    function postAnalyze(sm) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/analysisBarCodeCommon";
        var data = {
            values: {
                tm: sm, //条码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {

                    var map = myobj.data;
                    for (var key in map) {
                        $("#" + key).val(map[key]);
                    }
                    //自动保存
                    saveAuto();
                } else if (myobj.code == '1') {

                    $("#boxnum").val("");
                    $("#boxnum").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }


    //托号监听回车事件
    $("#traynum").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var traynum = $(this).val();
        if (keycode == '13') {

            // 查询容器条码是否可以一键入库
            doSerchRsCode(traynum);
        }
    });

    // 查询容器条码是否可以一键入库
    function doSerchRsCode(rsBarcode) {
        console.log('rsBarcode', rsBarcode)
        //判断容器条码是否重复
        for (var i = 0; i < arrSave.length; i++) {
            if (rsBarcode == arrSave[i].rsBarcode) {
                $("#rsBarcode").val("");
                api.toast({
                    msg: '容器码已存在！',
                    duration: 3000
                });
                return;
            }
        }
        // 显示物料编码、物料名称、批次号、数量
        getBoxInfoByTray(rsBarcode, 1);

    }

    //查询托下的箱信息展示 flag=1 为初始扫描托号获取箱信息，不显示库转结果、库转信息列，
    //flag=2 为库转保存后返回显示，需要显示库转结果、库转信息列
    // 显示物料编码、物料名称、批次号、数量
    function getBoxInfoByTray(traynum, flag) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getHGPRKQRInfoByMrlNew";
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        var data = {
            values: {
                traynum: traynum,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    var list = myobj.list;
                    var listS = eval(myobj.listS);
                    var listC = eval(myobj.listC);
                    console.log('listS:', JSON.stringify(listS))
                    console.log('listC:', JSON.stringify(listC))
                    var html = "";
                    //$("#qty").val(list.length);
                    var qty = 0;
                    //遍历
                    console.log("flag:" + flag);
                    // for (var i = 0; i < list.length; i++) {
                    //     qty = qty + Number(list[i].qty);
                    //     html += "<tr style='text-align: center;background-color: #F5F5F5;color: black;font-size: 8px;'>";
                    //     // html += "<td name='ext01'>" + list[i].ext01 + "</td>";
                    //     html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                    //     html += "<td name='mrlName'>" + list[i].mrlName + "</td>";
                    //     html += "<td name='drawing'>" + list[i].drawing + "</td>";
                    //     html += "<td name='ext05'>" + list[i].ext05 + "</td>";
                    //     html += "<td name='qty'>" + list[i].qty + "</td>";
                    //     html += "</tr>";
                    // }

                    // $("#qty").val(qty);
                    rsCodeList = rsCodeList + "," + traynum;
                    doSerchRsCodeList(rsCodeList)

                    $api.html($api.byId("tbodyHtml"), html);
                    $("#traynum").focus();
                    $("#traynum").select();
                    var flag = "1"
                    if (arrSave.length > 0) {
                        for (var i = 0; i < arrSave.length; i++) {
                            if (traynum === arrSave[i].rsBarcode) {
                                flag = "0"
                            }
                        }
                    }

                    if (flag === "1") {
                        var model = {
                            mrlCode: listC[0].mrl_code,
                            rsBarcode: listC[0].ctBarCode,
                            mrlName: listC[0].mrl_name,
                            returnMsg: listC[0].returnMsg,
                            drawing: listC[0].drawing,
                            qty: listC[0].qty,
                        }
                        arrSave.push(model);

                        num = num + 1
                        $("#num").val(num);

                        // 容器条码信息
                        setTable(arrSave, listTotal);
                    }

                } else if (myobj.code == '1') {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#traynum").focus();
                    $("#traynum").select();

                    $("#traynum").val("");
                    $("#qty").val("");
                }
            }
        })
    }

    function doSerchRsCodeList(rsCodeList) {
        console.log(2222222222)
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSerchRsCodeList";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                rsCodeList: rsCodeList,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                console.log(333333333)
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    var listS = eval(myobj.listS);
                    var html = "";
                    var qty = 0;
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        qty = qty + Number(list[i].qty);
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                        html += "<td name='drawing'>" + list[i].drawing + "</td>";
                        html += "<td name='qty'>" + list[i].qty + "</td>";
                        html += "</tr>";
                    }
                    console.log(list.length)
                    console.log(qty)
                    $api.html($api.byId("tbodyHtml"), html);
                    $("#qty").val(qty);

                    $("#rsBarcode").val("");
                } else if (myobj.code == '1') {
                    $("#rsBarcode").val("");
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    // 容器条码信息
    function setTable(list, listNew) {
        var html = "";
        console.log('容器条码返回信息:', JSON.stringify(list))
        for (var i = 0; i < list.length; i++) {
            if (listNew != undefined && listNew.some(function (item) { return item.trayyinfoid === list[i].rsBarcode; })) {
                html += "<li class='sortable ui-selectee ui-sortable' style='margin:3px;border-color: red;border-width: 2px;border-style: solid;'>";
                html += "<ul class='aui-list aui-media-list ui-selectee'>";
                html += "<li class='aui-list-item  ui-selectee'>";
                html += "<div class='aui-media-list-item-inner ui-selectee'>";
                html += "<div class='aui-list-item-inner ui-selectee'>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>容器条码：</div>";
                html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].rsBarcode + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料号：</div>";
                html += "<div class='aui-list-item-inner ui-selectee' style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].mrlCode + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>规格：</div>";
                html += "<div class='aui-list-item-inner ui-selectee' style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].drawing + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名称：</div>";
                html += "<div class='aui-list-item-inner ui-selectee' style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].mrlName + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量：</div>";
                html += "<div class='aui-list-item-inner ui-selectee' style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].qty + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 50%;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作结果：</div>";
                html += "<div class='aui-list-item-inner ui-selectee'>" + listNew.find(function (item) { return item.trayyinfoid === list[i].rsBarcode; }).message + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'></div>";
                html += "<div class='aui-list-item-inner ui-selectee'></div>";
                html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background:red;color:#f5f5f5;' onclick='remove(\"" + list[i].rsBarcode + "\");'>移除</div>";
                html += "</div>";
                html += "</div>";
                html += "</li>";
                html += "</ul>";
                html += "</li>";
            } else {
                html += "<li class='sortable ui-selectee ui-sortable' style='margin:3px;'>";
                html += "<ul class='aui-list aui-media-list ui-selectee'>";
                html += "<li class='aui-list-item  ui-selectee'>";
                html += "<div class='aui-media-list-item-inner ui-selectee'>";
                html += "<div class='aui-list-item-inner ui-selectee'>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>容器条码：</div>";
                html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].rsBarcode + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料号：</div>";
                html += "<div class='aui-list-item-inner ui-selectee' style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].mrlCode + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>规格：</div>";
                html += "<div class='aui-list-item-inner ui-selectee' style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].drawing + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料名称：</div>";
                html += "<div class='aui-list-item-inner ui-selectee'  style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].mrlName + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量：</div>";
                html += "<div class='aui-list-item-inner ui-selectee' style='overflow:hidden;white-space:nowrap;text-overflow:ellipsis'>" + list[i].qty + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'></div>";
                html += "<div class='aui-list-item-inner ui-selectee'></div>";
                html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background:red;color:#f5f5f5;' onclick='remove(\"" + list[i].rsBarcode + "\");'>移除</div>";
                html += "</div>";
                html += "</div>";
                html += "</li>";
                html += "</ul>";
                html += "</li>";
            }
        }
        $api.html($api.byId("tbodyHtmlS"), html);
    };

    // 移除容器条码信息
    function remove(rsBarcode) {
        for (var i = 0; i < arrSave.length; i++) {
            if (arrSave[i].rsBarcode == rsBarcode) {
                num = num - 1;
                arrSave.splice(i, 1)
                $("#num").val(num);
                setTable(arrSave, listTotal);
            }

        }

        // 将逗号拼接的字符串转换为数组
        var arr = rsCodeList.split(',');

        // 使用filter方法过滤掉指定的值
        arr = arr.filter(function(item) {return item !== rsBarcode});

        // 将数组转换回逗号拼接的字符串
        rsCodeList = arr.join(',');

        // console.log('将数组转换回逗号拼接的字符串rsCodeList:'+rsCodeList)
        if (rsCodeList.length > 0) {
            // 刷新表格数据
            doSerchRsCodeList(rsCodeList);
        } else {
            // 清空表格数据
            $api.html($api.byId("tbodyHtml"), "");
            arrSave = [];
            $("#qty").val("");
        }

    };

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>